Merge "Add meta=userinfo&uiprop=latestcontrib"
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / pagers / BlockListPagerTest.php
index 80df1d0..bd37c04 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 use MediaWiki\Block\Restriction\PageRestriction;
+use MediaWiki\Block\Restriction\NamespaceRestriction;
 use MediaWiki\MediaWikiServices;
 use Wikimedia\TestingAccessWrapper;
 
@@ -15,13 +16,18 @@ class BlockListPagerTest extends MediaWikiTestCase {
         * @dataProvider formatValueEmptyProvider
         * @dataProvider formatValueDefaultProvider
         * @param string $name
-        * @param string $value
         * @param string $expected
         */
-       public function testFormatValue( $name, $value, $expected, $row = null ) {
+       public function testFormatValue( $name, $expected = null, $row = null ) {
                $this->setMwGlobals( [
                        'wgEnablePartialBlocks' => false,
                ] );
+               // Set the time to now so it does not get off during the test.
+               MWTimestamp::setFakeTime( MWTimestamp::time() );
+
+               $value = $name === 'ipb_timestamp' ? MWTimestamp::time() : '';
+               $expected = $expected ?? MWTimestamp::getInstance()->format( 'H:i, j F Y' );
+
                $row = $row ?: new stdClass;
                $pager = new BlockListPager( new SpecialPage(),  [] );
                $wrappedPager = TestingAccessWrapper::newFromObject( $pager );
@@ -29,6 +35,9 @@ class BlockListPagerTest extends MediaWikiTestCase {
 
                $formatted = $pager->formatValue( $name, $value );
                $this->assertEquals( $expected, $formatted );
+
+               // Reset the time.
+               MWTimestamp::setFakeTime( false );
        }
 
        /**
@@ -38,17 +47,13 @@ class BlockListPagerTest extends MediaWikiTestCase {
                return [
                        [
                                'test',
-                               '',
                                'Unable to format test',
                        ],
                        [
                                'ipb_timestamp',
-                               wfTimestamp( TS_UNIX ),
-                               date( 'H:i, j F Y' ),
                        ],
                        [
                                'ipb_expiry',
-                               '',
                                'infinite<br />0 minutes left',
                        ],
                ];
@@ -76,31 +81,26 @@ class BlockListPagerTest extends MediaWikiTestCase {
                return [
                        [
                                'test',
-                               '',
                                'Unable to format test',
                                $row,
                        ],
                        [
                                'ipb_timestamp',
-                               wfTimestamp( TS_UNIX ),
-                               date( 'H:i, j F Y' ),
+                               null,
                                $row,
                        ],
                        [
                                'ipb_expiry',
-                               '',
                                'infinite<br />0 minutes left',
                                $row,
                        ],
                        [
                                'ipb_by',
-                               '',
                                $row->ipb_by_text,
                                $row,
                        ],
                        [
                                'ipb_params',
-                               '',
                                '<ul><li>account creation disabled</li><li>cannot edit own talk page</li></ul>',
                                $row,
                        ]
@@ -109,9 +109,13 @@ class BlockListPagerTest extends MediaWikiTestCase {
 
        /**
         * @covers ::formatValue
+        * @covers ::getRestrictionListHTML
         */
        public function testFormatValueRestrictions() {
-               $this->setMwGlobals( 'wgArticlePath', '/wiki/$1' );
+               $this->setMwGlobals( [
+                       'wgArticlePath' => '/wiki/$1',
+                       'wgScript' => '/w/index.php',
+               ] );
 
                $pager = new BlockListPager( new SpecialPage(),  [] );
 
@@ -134,7 +138,10 @@ class BlockListPagerTest extends MediaWikiTestCase {
                $pageId = $page['id'];
 
                $restrictions = [
-                       ( new PageRestriction( 0, $pageId ) )->setTitle( $title )
+                       ( new PageRestriction( 0, $pageId ) )->setTitle( $title ),
+                       new NamespaceRestriction( 0, NS_MAIN ),
+                       // Deleted page.
+                       new PageRestriction( 0, 999999 ),
                ];
 
                $wrappedPager = TestingAccessWrapper::newFromObject( $pager );
@@ -146,11 +153,21 @@ class BlockListPagerTest extends MediaWikiTestCase {
                        // and must not depend on a localisation message.
                        // TODO: Mock the message or consider using qqx.
                        . wfMessage( 'blocklist-editing' )->text()
-                       . '<ul><li><a href="/wiki/Victor_Frankenstein" title="'
+                       . '<ul><li>'
+                       . wfMessage( 'blocklist-editing-page' )->text()
+                       . '<ul><li>'
+                       . '<a href="/wiki/Victor_Frankenstein" title="'
                        . $pageName
                        . '">'
                        . $pageName
-                       . '</a></li></ul></li></ul>',
+                       . '</a></li></ul></li><li>'
+                       . wfMessage( 'blocklist-editing-ns' )->text()
+                       . '<ul><li>'
+                       . '<a href="/w/index.php?title=Special:AllPages&amp;namespace=0" title="'
+                       . 'Special:AllPages'
+                       . '">'
+                       . wfMessage( 'blanknamespace' )->text()
+                       . '</a></li></ul></li></ul></li></ul>',
                        $formatted
                );
        }
@@ -229,7 +246,7 @@ class BlockListPagerTest extends MediaWikiTestCase {
 
                $restriction = $restrictions[0];
                $this->assertEquals( $page->getId(), $restriction->getValue() );
-               $this->assertEquals( $page->getId(), $restriction->getTitle()->getArticleId() );
+               $this->assertEquals( $page->getId(), $restriction->getTitle()->getArticleID() );
                $this->assertEquals( $title->getDBKey(), $restriction->getTitle()->getDBKey() );
                $this->assertEquals( $title->getNamespace(), $restriction->getTitle()->getNamespace() );